import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-07-22
 * Time: 22:06
 */
public class test2 {
    public List<Integer> findAnagrams(String s, String p) {
        if (s.length()<p.length()){
            return new ArrayList<>();
        }
        List<Integer> ret = new ArrayList<Integer>();
        int[] hash = new int[128];
        for(int i=0;i<p.length();i++){
            hash[p.charAt(i)]++;
        }
        int left=0,right=0;
        while (right<s.length()){
            hash[s.charAt(right)]--;
            while (hash[s.charAt(right)]<0){
                hash[s.charAt(left)]++;
                left++;
            }
            if(right-left+1==p.length()){
                ret.add(left);
            }
            right++;
        }
        return ret;
    }
}
